<%
  module_name = ["gcp_#{object.__product.api_name}",
                 object.name.underscore,
                 'info'].join('_')
  module_name = "google.cloud.#{module_name}" unless @__example&.provider&.is_a?(Provider::Ansible::Devel)
-%>
- name: verify that <%= object.name.underscore -%> was <%= lines(verbs[_state.to_sym]) -%>
  <%= module_name -%>:
<%# GCE filters use the filters: notation and are different than most other filters -%>
<% if object.facts.has_filters && object.facts.filter.gce? -%>
      filters:
         - name = <%= name_parameter %>
<% end #if object.facts.has_filters -%>
<%# Most filters have a number of parameters that take in a single value.
  # We'll grab those values straight from the hand-written example to
  # ensure they match.
-%>
<% @parameters.each do |k, v| -%>
<%
  value = if v.include?('{{')
            "\"#{v}\""
          else
            v
          end
-%>
      <%= k -%>: <%= lines(value) -%>
<% end -%>
      project: "{{ gcp_project }}"
      auth_kind: "{{ gcp_cred_kind }}"
      service_account_file: "{{ gcp_cred_file }}"
      scopes:
        - <%= lines(object.__product.scopes[0]) -%>
  register: results
- name: verify that command succeeded
  assert:
    that:
<% if object.facts.test && _state == 'present' -%>
      - <%= lines(object.facts.test.exists) -%>
<% elsif object.facts.test && _state == 'absent' -%>
      - <%= lines(object.facts.test.does_not_exist) -%>
<% else # object.facts.test -%>
<% if object.facts.has_filters -%>
      - results['resources'] | length == <%= _state == 'present' ? 1 : 0 %>
<% else # object.has_filters -%>
<% # use maps on names to make tests less flakey -%>
<% if object.all_user_properties.any? { |x| x.name == 'name' } -%>
      - results['resources'] | map(attribute='name') | select("match", ".*<%= name_parameter -%>.*") | list | length == <%= _state == 'present' ? 1 : 0 %>
<% else -%>
      - results['resources'] | length <%= _state == 'present' ? '>= 1' : '== 0' %>
<% end # x.name == 'name' -%>
<% end  # object.has_filters -%>
<% end # object.facts.test -%>
